const index = '/pages/index/main'

const debug = process.env.NODE_ENV === "development"

function build(params){
    let queryString = []
    for(let i in params){
        queryString.push(encodeURIComponent(i) + '=' + encodeURIComponent(params[i]) )
    }
    return queryString.join('&')
}

export function itemUrl(params){
    const url = index + '?' + build({...params, route: 'item'})
    if(debug) console.log(url)
    return url
}

export function groupItem(params){
    const url = index + '?' + build({...params, route: 'groupItem'})
    if(debug) console.log(url)
    return url
}

export function searchItem(params){
    const url = index + '?' + build({...params, route: 'searchItem'})
    if(debug) console.log(url)
    return url
}

export function groupBuy(params){
    const url = index + '?' + build({...params, route: 'groupBuy'})
    if(debug) console.log(url)
    return url
}

export function goodsList(params){
    const url = index + '?' + build({...params, route: 'goodsList'})
    if(debug) console.log(url)
    return url
}

export function shareList(params){
    const url = index + '?' + build({...params, route: 'shareList'})
    if(debug) console.log(url)
    return url
}

export function h5Url(params){
    const url = index + '?' + build({...params, route: 'h5Url'})
    if(debug) console.log(url)
    return url
}

export function seckill(params){
    const url = index + '?' + build({...params, route: 'seckill'})
    if(debug) console.log(url)
    return url
}

export function seckillItem(params){
    const url = index + '?' + build({...params, route: 'seckillItem'})
    if(debug) console.log(url)
    return url
}

export function specialList(params){
    const url = index + '?' + build({...params, route: 'specialList'})
    if(debug) console.log(url)
    return url
}

export function special(params){
    const url = index + '?' + build({...params, route: 'special'})
    if(debug) console.log(url)
    return url
}


export function routeTo(options){
    if(options.route){
        let url
        switch(options.route){
            case 'item':
               url = `/pages/detail/main?id=${options.id}`
            break
            case 'groupItem':
               url = `/pages/groupItem/main?id=${options.id}`
            break
            case 'searchItem':
               url = `/pages/searchItem/main?id=${options.id}&coupon_amount=${options.coupon_amount}`
            break
            case 'groupBuy':
               url = `/pages/groupBuy/main`
            break
            break
            case 'goodsList':
               url = `/pages/goodsList/main?id=${options.id}`
            break
            case 'shareList':
               url = `/pages/shareList/main?id=${options.id}`
            break
            case 'h5Url':
                url = `/pages/questions/main?url=${options.url}&title=${options.title}`
            break
            case 'seckill':
                url = `/pages/seckill/main`
            break
            case 'seckillItem':
                url = `/pages/seckillItem/main?id=${options.id}`
            break
            case 'specialList':
                url = `/pages/specialList/main`
            break
            case 'special':
                url = `/pages/special/main?id=${options.id}`
            break
        }
        console.log(url)
            wx.navigateTo({
                url
            })
    }
}
